package com.platform.modules.quality.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.common.utils.Query;
import com.platform.modules.quality.dao.QlyAcceptanceDao;
import com.platform.modules.quality.dao.QlyAcceptancePersonnelDao;
import com.platform.modules.quality.entity.QlyAcceptanceEntity;
import com.platform.modules.quality.entity.QlyAcceptancePersonnelEntity;
import com.platform.modules.quality.service.QlyAcceptanceService;
import com.platform.modules.quality.vo.QlyAcceptanceStatusQuantityByAppVo;

@Service
public class QlyAcceptanceServiceImpl extends ServiceImpl<QlyAcceptanceDao, QlyAcceptanceEntity> implements QlyAcceptanceService {

    private static final Logger logger = LoggerFactory.getLogger(QlyAcceptanceServiceImpl.class);
    
    @Autowired
    QlyAcceptancePersonnelDao qlyAcceptancePersonnelDao;
    
    @Override
	public List<QlyAcceptanceEntity> queryList(Map<String, Object> params) {
    	params.put("sidx", "ACC_TIME");
        params.put("asc", false);
		return baseMapper.selectList(params) ;
	}
    
    @Override
    public Page<QlyAcceptanceEntity> queryPage(Map<String, Object> params) {
        //排序
        params.put("sidx", "ACC_TIME");
        params.put("asc", false);
        Page<QlyAcceptanceEntity> page = new Query<QlyAcceptanceEntity>(params).getPage();
        List<QlyAcceptanceEntity> list = baseMapper.selectList(page, params);
        return page.setRecords(list);
    }

	@Override
	public Page<QlyAcceptanceEntity> queryPageByApp(Map<String, Object> params) {
        //排序
        params.put("sidx", "ACC_TIME");
        params.put("asc", false);
        Page<QlyAcceptanceEntity> page = new Query<QlyAcceptanceEntity>(params).getPage();
        List<QlyAcceptanceEntity> list = baseMapper.selectList(page, params);
        return page.setRecords(list);
	}

	@Override
	public void saveAll(QlyAcceptanceEntity qlyAcceptanceEntity) {
		baseMapper.insert(qlyAcceptanceEntity);
		List<QlyAcceptancePersonnelEntity> personnels = qlyAcceptanceEntity.getPersonnels();
		for(QlyAcceptancePersonnelEntity personnel : personnels) {
			personnel.setAccId(qlyAcceptanceEntity.getAccId());
			qlyAcceptancePersonnelDao.insert(personnel);
		}
	}

	@Override
	public QlyAcceptanceStatusQuantityByAppVo statusQuantity(String prjId) {
		QlyAcceptanceStatusQuantityByAppVo vo = new QlyAcceptanceStatusQuantityByAppVo();
		vo.setPrjId(prjId);
		vo.setAllQuantity(0L);
		vo.setQualifiedQuantity(0L);
		vo.setDisqualifiedQuantity(0L);

//		List<Map<String,Object>> list = baseMapper.statusQuantity(prjId);
//		for(Map<String,Object> m : list) {
//			
//		}
		return vo;
	}

	

}
